package chars;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.Charset;

public class BufferedWriterTest {

	public static void main(String[] args) throws IOException {
		
		System.out.println( "default charset name :" + Charset.defaultCharset().name() );
		
		File file = new File( "buffered-writer.txt" );
		
		OutputStream output = new FileOutputStream( file );
		
		Charset cs = Charset.forName( "GBK" ); // 获取 GBK 编码
		
		Writer writer = new OutputStreamWriter( output ,  cs );
		
		BufferedWriter bw = new BufferedWriter( writer );
		
		bw.append( "青海长云暗雪山" );
		bw.newLine();
		
		bw.write( "孤城遥望玉门关" );
		bw.newLine();
		
		bw.close();
		writer.close();
		output.close();
	}

}
